﻿@using System.ComponentModel.DataAnnotations;
@using System.Text.Json;

    <Form Model="@model"
          LabelCol="new ColLayoutParam { Span = 8 }"
          WrapperCol="new ColLayoutParam { Span = 16 }"
          OnFinish="OnFinish"
          OnFinishFailed="OnFinishFailed">
        <FormItem Label="Username">
            <Input @bind-Value="@context.Username" />
        </FormItem>
        <FormItem Label="Password">
            <InputPassword @bind-Value="@context.Password" />
        </FormItem>
        <FormItem WrapperCol="new ColLayoutParam{ Offset = 8, Span = 16 }">
            <Checkbox @bind-Value="context.RememberMe">Remember me</Checkbox>
        </FormItem>
        <FormItem WrapperCol="new ColLayoutParam{ Offset = 8, Span = 16 }">
            <Button Type="@ButtonType.Primary" HtmlType="submit">
                Submit
            </Button>
        </FormItem>
    </Form>
@code
{
    public class Model
    {
        [Required]
        public string Username { get; set; }
        [Required]
        public string Password { get; set; }
        public bool RememberMe { get; set; } = true;
    }

    private Model model = new Model();

    private void OnFinish(EditContext editContext)
    {
        Console.WriteLine($"Success:{JsonSerializer.Serialize(model)}");
    }

    private void OnFinishFailed(EditContext editContext)
    {
        Console.WriteLine($"Failed:{JsonSerializer.Serialize(model)}");
    }
}